package socketmvc.core.codec;

import socketmvc.core.packets.basic.IPacket;

import java.nio.ByteBuffer;

/**
 * packet解编码器
 * @author xueyanjun
 */
public interface IPacketCodec {

    /**
     * 解码
     * @param buffer bytes
     * @return packet
     */
    IPacket decode(ByteBuffer buffer);

    /**
     * 编码
     * @param packet packet
     * @return bytes
     */
    ByteBuffer encode(IPacket packet);


    /**
     * 当前解析器所属协议
     * @return 协议对象
     */
    byte protocolVersion();

    /**
     * 获取可读长度
     * @param buffer buf
     * @return 长度
     */
    default int getBufferReadableLength(ByteBuffer buffer){
        return buffer.limit() - buffer.position();
    }



}
